package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.controller.request.QuestionPageRequest;
import com.example.springboot.entity.Question;
import com.example.springboot.service.IQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin

@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    IQuestionService questionService;
@PostMapping("/save")
public Result save(@RequestBody Question question){


    questionService.save(question);
    return  Result.success();
}
    @PutMapping("/update")
    public Result update(@RequestBody Question question){


        questionService.update(question);
        return  Result.success();
    }
    @DeleteMapping("/delete/{id}")
    public   Result delete(@PathVariable Integer id) {
       questionService.deleteById(id);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
       Question question = questionService. getById(id);
        return Result.success(question);

    }




    @GetMapping("/list")
    public Result list() {
        List<Question> questions = questionService.list();
        return Result.success(questions);

    }

    @GetMapping("/page")
    public Result page(QuestionPageRequest questionPageRequest) {

        return Result.success(questionService.page(questionPageRequest));
    }
}